package com.example.sisko_app;

import com.example.services.RandomServices;

import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.os.Vibrator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.Toast;

public class RandomActivity extends Activity implements View.OnClickListener {

	private ImageButton rollButton;
	private Spinner spinner;
	private Intent switchRestaurant;
	private Handler TimeHandler;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_random);
		
		rollButton = (ImageButton)findViewById(R.id.random_buttonRoll);
        rollButton.setOnClickListener(this);
        
        spinner = (Spinner) findViewById(R.id.random_spinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.kategorie_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_random, menu);
		return true;
	}
	
	public void onClick(View v) {
        Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
        findViewById(R.id.random_buttonRoll).startAnimation(shake);
        Toast.makeText(this, "Aaaabfahrt", Toast.LENGTH_SHORT).show();
        
        
        Vibrator Vib = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
        Vib.vibrate(1000);
        
        switchRestaurant = new Intent(this, RestaurantActivity.class);
        RandomServices RdServ = new RandomServices();       
        
        switchRestaurant.putExtra("LocID",RdServ.getRandomLocation(this, spinner.getSelectedItem().toString()));
        
        TimeHandler = new Handler();
        TimeHandler.postDelayed(startRestaurant, 1000);
        
        
    }
	
	private Runnable startRestaurant = new Runnable() {
				
		@Override
		public void run() {
		
	        startActivity(switchRestaurant);
			
		}
	};

}
